import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from "@/layout";

Vue.use(VueRouter)
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(to) {
  return VueRouterPush.call(this, to).catch(err => err)
}


const routes = [
  {
    path: '/',
    component: Layout,
    redirect: '/login',
    children: [
      {
        path: '/index',
        component: () => import('@/views/Home'),
        meta: { title: '首页' }
      }, {
        path: '/test',
        component: () => import('@/views/test'),
        meta: { title: '测试' }
      },
      {
        path: '/courses',
        component: () => import('@/views/Courses'),
        meta: { title: '公开课程' }
      },
      {
        path: '/history',
        component: () => import('@/views/history'),
        meta: { title: '观看记录' }
      },
      {
        path: '/course',
        component: () => import('@/views/courseDetail'),
        meta: { title: '课程视频' }
      },
      {
        path: '/question',
        component: () => import('@/views/Question'),
        meta: { title: '公开题库' }
      },
      {
        path: '/exam',
        component: () => import('@/views/exam'),
        meta: { title: '试卷中心' }
      },
      {
        path: '/topic',
        component: () => import('@/views/Question/child/topic'),
        meta: { title: '练习' }
      },
      {
        path: '/personal',
        component: () => import('@/views/Personal'),
        meta: { title: '个人中心' },
        redirect: '/personal/plan',
        children: [
          {
            path: 'plan',
            component: () => import('@/views/Personal/child/plan/plan'),
            meta: { title: '学习计划' }
          },
          {
            path: 'question',
            component: () => import('@/views/Personal/child/question'),
            meta: { title: '个人题库' }
          },
          {
            path: 'exam',
            component: () => import('@/views/Personal/child/exam/exam'),
            meta: { title: '我的考试' }
          },
          {
            path: 'info',
            component: () => import('@/views/Personal/child/profile/info'),
            meta: { title: '个人信息' }
          }
        ]
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login')
  },
  {
    path: '/examInfo',
    component: () => import('@/views/exam/info')
  }
]





const router = new VueRouter({
  routes
})


export function resetRouter() {
  const newRouter = router
  router.matcher = newRouter.matcher // reset router
}

export default router
